// components/v-piker/v-piker.js
const numbers1 = []; //天
for (let i = 1; i <= 365; i++) {
  numbers1.push(i)
}
const numbers2 = []; //月
for (let i = 1; i <= 23; i++) {
  numbers2.push(i)
}
const numbers3 = []; //年
for (let i = 1; i <= 1; i++) {
  numbers3.push(i)
}

Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    numbers: numbers1,
    number: 1,
    units: ['天', '月', '年', ],
    unit: '天',
    value: [0, 0],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    bindChange: function(e) {
      const val = e.detail.value
      if (this.data.unit !== this.data.units[val[1]]) {
        if (this.data.units[val[1]] === '月') {
          this.setData({
            value: [0, 1],
            numbers: numbers2,
            unit: '月',
            number: 1
          })
        } else if (this.data.units[val[1]] === '年') {
          this.setData({
            value: [0, 2],
            numbers: numbers3,
            unit: '年',
            number: 1
          })
        } else {
          this.setData({
            value: [0, 0],
            numbers: numbers1,
            unit: '天',
            number: 1
          })
        }
      } else {
        this.setData({
          number: this.data.numbers[val[0]],
          unit: this.data.units[val[1]]
        });
      }

      //传送数据
      const myEventDetail = {
        number: this.data.number,
        unit: this.data.unit
      } // detail对象，提供给事件监听函数
      const myEventOption = {} // 触发事件的选项
      this.triggerEvent('subevent', myEventDetail, myEventOption)
    }
  }
})